#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
int w[N], s[N];
int n, m;
bool cmp(int a, int b)
{
	if (s[a] != s[b]) {
		return s[a] < s[b];
	}
	return a < b;
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		w[i] = i;
		int j = w[i];
		while (j) {
			s[i] += j % 10;
			j /= 10;
		}
	}
	sort(w + 1, w + n + 1, cmp);
	cout << w[m] << endl;
	return 0;
}